package com.restcloud.utils;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

public class TimeUtil {

    public static void main(String[] args) {
        String inputDate = "2024-03-07";
        String processedDate = getLastSecondOfDay(inputDate);
        System.out.println("处理后的时间为: " + processedDate);
    }
    public static String dateTime(){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhhmmss");
        return sdf.format(new Date());
    }

    public static String getLastSecondOfDay(String dateStr) {
        // 将输入的日期字符串转换为 LocalDateTime 对象
        LocalDateTime dateTime = LocalDateTime.parse(dateStr + "T00:00:00");

        // 处理为当天的最后一秒
        LocalDateTime endOfDay = dateTime.withHour(23).withMinute(59).withSecond(59);

        // 格式化输出为 yyyy-MM-dd HH:mm:ss
        return endOfDay.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
    }
}